home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Development Tools & Languages / HyperCard Related / APDA HyperCard Toolkits / AppleTalk ToolKit / NBP / NBPLookupNames.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-07  |  4.6 KB  |  166 lines  |  [TEXT/MPS ]

  1. /*******************************************************************\
  2. *    file:         NBPLookupNames.c                                    *
  3. *    version:    1.06ß                                                 *
  4. *                                                                     *
  5. * Once connected to the network, look up all other entities of the    *
  6. * same type as this entity.                                            *
  7. * -----------------------------------------------------------------    *
  8. * By:    Donald Koscheka, Greg Kimberly                                *
  9. * Date:    24-Sept-87                                                    *
  10. * ©    Copyright 1987, Apple Computer, Inc.                            *
  11. *    All Rights Reserved                                                *
  12. *                                                                    *
  13. * -----------------------------------------------------------------    *
  14. *                        Modification History                        *
  15. * -----------------------------------------------------------------    *
  16. *  Date           | By    |                     Description                    *
  17. * -----------------------------------------------------------------    *
  18. * 9/24/87    | GK    | file created                                    *
  19. * 10/6/87    | DK    | added passing of type,zone,num,count,interval    *
  20. * 14-Jan-87    | DK    | modified to reflect decoupling of NBP & ATP    *
  21. * 22-Feb-88 | DK    | Move all locked handles high                    *
  22. * -----------------------------------------------------------------    *
  23. \*******************************************************************/
  24.  
  25. /*******************************************************************\
  26.                             Build Sequence
  27.     
  28. C -q2 -g -o "{hpo}"NBPLookupNames.c.o "{nbp}"NBPLookupNames.c
  29.     link  -sn Main=NBPLookupNames -sn STDIO=NBPLookupNames ∂
  30.          -sn INTENV=NBPLookupNames -rt XFCN=302 ∂
  31.          -m NBPLOOKUPNAMES ∂
  32.          "{hpo}"NBPLookupNames.c.o "{hpo}"atalkxcmd.c.o "{hpo}"xcmdutils.c.o ∂
  33.          "{CLibraries}"CInterface.o ∂
  34.          "{Libraries}"Interface.o ∂
  35.          -o "{hp}"HyperPeople
  36.  
  37. \*******************************************************************/
  38.  
  39. #include <Types.h>
  40. #include <Memory.h>
  41. #include <Resources.h>
  42. #include <OSUtils.h>
  43. #include <appleTalk.h>
  44. #include <HyperXCmd.h>
  45. #include <atalkXCMD.h>
  46. #include <XCMDUtils.h>
  47.  
  48.  
  49. pascal void NBPLookupNames(paramPtr )
  50.     XCmdBlockPtr    paramPtr;    
  51. /**********************************
  52. * Lookup  entities of the requested 
  53. * type and zone (up to num elements):
  54. *
  55. *    params[0]    char    *theType
  56. *    params[1]    char    *theZone
  57. *    params[2]    short    num
  58. *    params[3]    count
  59. *    params[4]    interval
  60. *
  61. * Entity names are returned in a list:
  62. * name,type\r
  63. *
  64. * defaults are: name    = '='
  65. *                type    = '='
  66. *                zone    = '*'
  67. *                num        = 10
  68. *                count    = 2
  69. *                interval= 8
  70. *
  71. * Note: we don't set the granularity
  72. * to lookup single names because ATConfirm
  73. * is a more efficient method of doing that.
  74. **********************************/
  75. {
  76.     NBPBlock     *nbp;
  77.     short         total,i, count, interval, num;
  78.     char        theType[34], theZone[34];
  79.     char        outStr[256];
  80.     EntityName     eName;
  81.     AddrBlock     eAddr;    
  82.     char         **stringSpace, newline[2], comma[2];
  83.     
  84.     nbp = (NBPBlock *)RetrieveHandle( paramPtr, GLOBALNBPDATA );
  85.     if( !nbp ){
  86.         paramPtr->returnValue = ErrorReturn( DEFAULT_ERROR );
  87.         return;
  88.     }
  89.  
  90.     if( !paramPtr->params[0] ){    /*** type not specified ***/
  91.         theType[0] = '\1';
  92.         theType[1] = '=';
  93.     }
  94.     else{
  95.         HLock( paramPtr->params[0] );
  96.         ZeroToPas( paramPtr, *(paramPtr->params[0]), theType );
  97.         HUnlock( paramPtr->params[0] );
  98.     }
  99.     
  100.     if( !paramPtr->params[1] ){    /*** zone not specified ***/
  101.         theZone[0] = '\1';
  102.         theZone[1] = '*';
  103.     }
  104.     else{
  105.         HLock( paramPtr->params[1] );
  106.         ZeroToPas( paramPtr, *(paramPtr->params[1]), theZone );
  107.         HUnlock( paramPtr->params[1] );
  108.     }
  109.     
  110.     if( paramPtr->params[2] ){
  111.         HLock( paramPtr->params[2] );
  112.         c2pstr( *(paramPtr->params[2] ));
  113.         num = (short)StrToNum( paramPtr, *(paramPtr->params[2]) );
  114.         HUnlock( paramPtr->params[2] );
  115.     }
  116.     else
  117.         num = MAXNODES;    
  118.     
  119.     if( paramPtr->params[3] ){
  120.         HLock( paramPtr->params[3] );
  121.         c2pstr( *(paramPtr->params[3] ));
  122.         count = (short)StrToNum( paramPtr, *(paramPtr->params[3]) );
  123.         HUnlock( paramPtr->params[3] );
  124.     }
  125.     else
  126.         count = 2;
  127.         
  128.     if( paramPtr->params[4] ){    
  129.         HLock( paramPtr->params[4] );
  130.         c2pstr( *(paramPtr->params[4] ));
  131.         interval = (short)StrToNum( paramPtr, *(paramPtr->params[4]) );
  132.         HUnlock( paramPtr->params[4] );
  133.     }
  134.     else
  135.         interval = 8;    
  136.  
  137.     total = Lookup( nbp, theType, theZone, num, count, interval );
  138.  
  139.     stringSpace     = NewHandle( (long)(sizeof( EntityName ) * total) );
  140.     MoveHHi( stringSpace );
  141.     HLock( stringSpace );
  142.     **stringSpace     = '\0';
  143.     newline[0]         = '\r';
  144.     newline[1]         = '\0';
  145.     comma[0]        = ',';
  146.     comma[1]        = '\0';
  147.     
  148.     for ( i=1; i <= total; i++ ){            /*** return the list of entities ***/
  149.         if( ExtractName( nbp, i, &eName, &eAddr)){
  150.             p2cstr( &(eName.objStr) );
  151.             p2cstr( &(eName.typeStr) );
  152.  
  153.             outStr[0] = '\0';
  154.             sappend( outStr,  &(eName.objStr) );
  155.             sappend( outStr, comma );
  156.             sappend( outStr, &(eName.typeStr) );
  157.             sappend( outStr, newline );
  158.             sappend( *stringSpace, outStr );
  159.         }
  160.     }
  161.     HUnlock( stringSpace );
  162.     paramPtr->returnValue = stringSpace;
  163. }
  164.  
  165.  
  166.